package com.hunliji.monitor.service.impl;

import com.hunliji.monitor.dao.mapper.ad.ConsumeBillMapper;
import com.hunliji.monitor.dao.model.dataobject.WalletConsumeDO;
import com.hunliji.monitor.dao.model.param.QueryWalletConsumeDataParam;
import com.hunliji.monitor.service.api.ConsumeService;
import com.hunliji.monitor.service.api.model.bo.WalletConsumeBO;
import com.hunliji.monitor.service.api.model.param.QueryWalletConsumeParam;
import com.hunliji.monitor.share.component.ComponentLocator;
import com.hunliji.monitor.share.component.sharding.ShardingFacade;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 消耗查询类
 * @author hunliji
 */
@Service
public class ConsumeServiceImpl implements ConsumeService {
    /**
     * 消耗表的前缀
     */
    private static final String CONSUME_BILL_PREFIX = "consume_bill";
    @Resource
    private ConsumeBillMapper consumeBillMapper;
    @Resource
    private ShardingFacade shardingFacade;
    /**
     * 通用查询接口
     * @param walletConsumeParam
     * @return
     */
    @Override
    public List<WalletConsumeBO> query(QueryWalletConsumeParam walletConsumeParam) {
        List<WalletConsumeBO> walletConsumeBOList = queryToday(walletConsumeParam);
        return walletConsumeBOList;
    }

    /**
     * 查询当天，当天数据是按照小时查询
     * @param walletConsumeParam
     * @return
     */
    private List<WalletConsumeBO> queryToday(QueryWalletConsumeParam walletConsumeParam){
        QueryWalletConsumeDataParam queryWalletConsumeDataParam = ComponentLocator.getConverter().convert(walletConsumeParam,QueryWalletConsumeDataParam.class);
        //设置table
        queryWalletConsumeDataParam.setTableName(shardingFacade.getTableNameForDayToYear(walletConsumeParam.getQueryStartTime(),CONSUME_BILL_PREFIX));
        List<WalletConsumeDO> walletConsumeDOList = consumeBillMapper.generalQuery(queryWalletConsumeDataParam);
        List<WalletConsumeBO> walletConsumeBOList = ComponentLocator.getConverter().convertList(walletConsumeDOList,WalletConsumeBO.class);
        return walletConsumeBOList;
    }
}
